package com.example.health_life.controller;

import com.example.health_life.Response;
import com.example.health_life.dao.Feedback;
import com.example.health_life.dto.FeedbackDTO;
import com.example.health_life.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @GetMapping("/feedbacks")
    public Response<List<Feedback>> getFeedbackList() {
        List<Feedback> feedbackList = feedbackService.getFeedbackList();
        return  Response.newSuccess(feedbackList);
    }

    @GetMapping("/feedbacks/{id}")
    public Response<Feedback> getFeedbackById(@PathVariable Integer id) {
        Feedback feedback = feedbackService.getFeedbackById(id);
        return  Response.newSuccess(feedback);
    }

    @GetMapping("/feedbacks/user/{userId}")
    public Response<List<Feedback>> getFeedbackByUserId(@PathVariable Integer userId) {
        List<Feedback> feedbackList = feedbackService.getFeedbackByUserId(userId);
        return  Response.newSuccess(feedbackList);
    }

    @GetMapping("/feedbacks/about/{aboutId}")
    public Response<List<Feedback>> getFeedbackByAbout( @PathVariable Integer aboutId) {
        List<Feedback> feedbackList = feedbackService.getFeedbackByAbout(aboutId);
        return  Response.newSuccess(feedbackList);
    }

    @PostMapping("/feedbacks")
    public Response<Integer> addFeedback(@RequestBody FeedbackDTO feedbackDTO) {
        return Response.newSuccess(feedbackService.addFeedback(
            feedbackDTO.getUserId(),
            feedbackDTO.getContent(),
            feedbackDTO.getAbout(),
            feedbackDTO.getPhone()
        ));
    }
}
